#!/usr/bin/env bash
# @sys: centos7.x+
# @date: 2022-02-23 10:59:50
# @author: hflxhn
# @email: hflxhn@163.com
# @info: test host lan
# @run: ./test_host_lan.sh



# 变量定义
read -p "please enter lan address (eg 172.16.0): " lan
if [[ -z $lan ]]; then
    exit 0;
fi


# ping 检测
for (( i = 1; i <= 255; i++ )); do
    address=${lan}.${i}

    ping ${address} -c1 -W1 &>/dev/null
    if [[ $? == 0 ]]; then
        echo -e "\033[32m${address} online"
    else
        echo -e "\033[31m${address} offline"
    fi
done
